# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libxslt

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1.28
pkgrel=4
pkgdesc="XML stylesheet transformation library (mingw-w64)"
arch=('any')
url="http://xmlsoft.org/XSLT/"
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-libxml2" "${MINGW_PACKAGE_PREFIX}-libgcrypt")
groups=("${MINGW_PACKAGE_PREFIX}")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('strip' 'staticlibs')
install=${_realname}-${CARCH}.install
source=("http://xmlsoft.org/sources/libxslt-${pkgver}.tar.gz"
    "libxslt-1.1.26-w64.patch"
    "libxslt-1.1.27-disable_static_modules.patch"
    "libxslt-1.1.28-win32-shared.patch"
    "libxslt.m4-libxslt-1.1.26.patch"
    '0002-python-linking-on.mingw.patch'
    '0003-fix-concurrent-directory-creation.all.patch'
    '0004-add-missing-include-for-python.all.patch'
    '0005-fix-freelocales-export.all.patch'
    '0006-no-undefined-tests.patch'
    '0007-use-mingw-C99-compatible-functions-{v}snprintf.patch')
md5sums=('9667bf6f9310b957254fdcf6596600b7'
         'b994c0d9df0f644e219cf63561ee0d4e'
         '05498030f492ffb0774869bacafe5fc1'
         '19646f155b518b40cb63e41270215964'
         '61b520bbd42006c16bbfc85bc5342b96'
         'a944fcf65f9948bb9dba325a8f6e7c5c'
         'cf3c1fb253a4a3bdeb099a0f6c55220a'
         '267c16ba85010d47a86827da1f339bdd'
         'ee6e3e375b8ea2f42c7039e13f14f0c8'
         '5723b8cad2aafb5a72ff97d342870f75'
         '4fc5c9dc73cb6e4d8d35e58c0d447f2a')

prepare() {
  cd "$srcdir/libxslt-${pkgver}"
  patch -p1 -i "${srcdir}/libxslt-1.1.26-w64.patch"
  patch -p1 -i "${srcdir}/libxslt-1.1.27-disable_static_modules.patch"
  patch -p1 -i "${srcdir}/libxslt-1.1.28-win32-shared.patch"
  patch -p1 -i "${srcdir}/libxslt.m4-libxslt-1.1.26.patch"

  patch -p1 -i "${srcdir}/0002-python-linking-on.mingw.patch"
  patch -p1 -i "${srcdir}/0003-fix-concurrent-directory-creation.all.patch"
  patch -p1 -i "${srcdir}/0004-add-missing-include-for-python.all.patch"
  patch -p1 -i "${srcdir}/0005-fix-freelocales-export.all.patch"
  patch -p1 -i "${srcdir}/0006-no-undefined-tests.patch"
  patch -p1 -i "${srcdir}/0007-use-mingw-C99-compatible-functions-{v}snprintf.patch"

  autoreconf -fi
}

build() {
  mkdir -p "$srcdir/build-${CARCH}" && cd "$srcdir/build-${CARCH}"
  $srcdir/libxslt-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --with-crypto \
    --with-plugins \
    --with-libxml-prefix=${MINGW_PREFIX} \
    --with-python=${MINGW_PREFIX}/bin/python2

  # Hack for mingw python
  pushd ${MINGW_PREFIX} > /dev/null
  export PREFIX_DEPS=`pwd -W`
  popd > /dev/null
  find . -type f -name "Makefile" -exec sed -i "s|${PREFIX_DEPS}|${MINGW_PREFIX}|g" {} \;
  make
}

package() {
  export MSYS2_ARG_CONV_EXCL="-//OASIS"
  cd "$srcdir/build-${CARCH}"
  make DESTDIR="$pkgdir" install
  #rm -r "${pkgdir}${MINGW_PREFIX}"/share
}

